Skip to content

Conversation

jonatsm
Copy link
Member

@jonatsm jonatsm commented Oct 8, 2026

Add Apollo Client to the frontend

The frontend can now talk to the backend through Apollo Client.

  • @apollo/client, rxjs and graphql@16 added (same graphql version as the backend)
  • graphql/client.ts: shared client, wrapped around the app with ApolloProvider
  • The client calls /project2/graphql. In dev, Vite proxies it to the backend; on the VM, Apache must do the same. No .env or CORS needed. VITE_GRAPHQL_URL overrides the URL.
  • graphql/queries.ts: first query (health)
  • Temporary BackendStatus footer showing connected / unavailable, with tests using MockedProvider
  • AGENTS.md updated (commands, folder structure, Apache proxy note)

⚠️ The JS bundle grew from 137 to 186 kB gzipped, and Vite now warns about bundle size. Splitting the code into lazy-loaded chunks could be a separate issue if we want to reduce the size. Should consider options to make it as sustainable as possible.

How to test

  1. npm install, then npm run dev:backend and npm run dev
  2. The footer shows "Backend: connected"
  3. Stop the backend and reload: "Backend: unavailable"

Closes #33

Install @apollo/client with its required rxjs and graphql
peers so the frontend can query the backend.

Refs #33
Forward /project2/graphql to the backend during development,
the same path Apache will proxy on the VM, so the frontend
uses one URL everywhere and avoids CORS.

Refs #33
Create a shared Apollo Client that sends queries to
/project2/graphql, or VITE_GRAPHQL_URL when set, and wrap
the app in ApolloProvider so any component can use useQuery.

Refs #33
Add the first GraphQL query in frontend/src/graphql/ and a
temporary BackendStatus footer that runs it on page load, showing
whether the frontend can reach the backend. Should be removed
once real queries exists.

Refs #33
Test the checking, connected and unavailable stats with
MockedProvider, so no running backend is needed.

Refs #33
@jonatsm jonatsm added this to the Partial submission 2 milestone Oct 8, 2026
@jonatsm jonatsm requested a review from a team as a code owner October 8, 2026 09:57
@jonatsm jonatsm linked an issue Oct 8, 2026 that may be closed by this pull request
4 tasks
Copy link
Member

@asgeija asgeija left a comment •

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, lint, build and tests pass for me. Two small things:

  • You removed the PORT=3002 note from AGENTS.md, but vite.config.ts now uses BACKEND_PORT. Can you add a note about that? Otherwise it just says "Backend: unavailable" if port 3001 is taken.

  • Add role="status" to the p in BackendStatus so screen readers pick up the change.

The bundle is a bit bigger now, but a separate issue for that is fine.

REstore the note on moving both servers to another port,
since the frontends´s BACKEND_PORT must match the backend´s
PORT. Add role="status" so screen readers announce the status change,
with a test for it.

Refs #33
@jonatsm
Copy link
Member Author

jonatsm commented Oct 8, 2026

Looks good, lint, build and tests pass for me. Two small things:

* You removed the PORT=3002 note from AGENTS.md, but vite.config.ts now uses BACKEND_PORT. Can you add a note about that? Otherwise it just says "Backend: unavailable" if port 3001 is taken.

* Add role="status" to the p in BackendStatus so screen readers pick up the change.

The bundle is a bit bigger now, but a separate issue for that is fine.

Added the PORT/BACKEND_PORT note back to AGENTS.md and role="status" on the footer, plus a test that checks the role.

@jonatsm jonatsm requested a review from asgeija October 8, 2026 10:44
Copy link
Member

@asgeija asgeija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now

@asgeija asgeija merged commit 27e8110 into main Oct 8, 2026
1 check passed
@asgeija asgeija deleted the 33-add-apollo-client-to-the-frontend branch October 8, 2026 11:30
Sign in to join this conversation on GitHub.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Apollo Client to the frontend
2 participants